#include "bsp_tick.h"

static volatile uint64_t mTick = 0;

void systick_init(uint32_t period) {
  /* Initialize the period to 1.00 ms */
  DL_SYSTICK_init(period);
  DL_SYSTICK_enableInterrupt();
  NVIC_SetPriority(SysTick_IRQn, 1);
  DL_SYSTICK_enable();
}
void systick_inc_tick(void) { mTick++; }
uint64_t systick_get_tick(void) { return mTick; }
void systick_set_tick(uint64_t tick) { mTick = tick; }
void systick_clear_tick(void) { mTick = 0; }
void delay_ms(uint64_t ms) {
  uint64_t tick = systick_get_tick();
  while (systick_get_tick() - tick < ms)
    ;
}
